# Replication Package

**"Where Does Demographic Capital Go? Bilateral Evidence from a Gravity Model"**

Working Paper, February 2026

## Requirements

- Python 3.10+
- pandas, numpy, scipy, statsmodels
- python-docx (for paper generation)
- imfp (for IMF data download)

Install: `pip install pandas numpy scipy statsmodels python-docx imfp`

## Directory Structure

```
replication/
├── README.md                  # This file
├── PROJECT_DOCUMENTATION.md   # Full technical documentation
├── WORKPLAN.md                # Research workplan and completed items
├── scripts/                   # All estimation scripts (run in order)
│   ├── phase1_download_data.py          # Download CPIS, CDIS, CEPII; construct panel
│   ├── phase2_estimation.py             # Main gravity models (2a-2f)
│   ├── phase3_cca_robustness.py         # CCA exclusion, jackknife, margins
│   ├── phase4_expand_yields.py          # Download additional bond yields
│   ├── phase4b_reestimate_expanded.py   # Re-estimate with 35-country yields
│   ├── phase5_ppml.py                   # PPML robustness
│   ├── phase5_projections.py            # Demographics-only projections
│   ├── phase5b_projections_ge.py        # Enhanced projections (WEO GDP + GE)
│   ├── phase6_financial_center_robustness.py  # Financial center exclusion
│   └── wald_tests.py                    # Joint significance tests
├── src/                       # Shared modules
│   ├── __init__.py
│   ├── model.py               # PanelGLS estimator
│   └── macro.py               # Macro utilities
├── data/
│   ├── raw/                   # Downloaded data (populated by phase1)
│   └── processed/             # Constructed panel (populated by phase1)
├── output/
│   └── tables/                # All estimation output (18 CSV files)
└── paper/
    ├── gravity_paper_20260219v1.md    # Paper source (Markdown)
    ├── gravity_paper_20260219v1.docx  # Paper (Word)
    ├── references.bib                  # Bibliography
    └── convert_to_docx.py             # MD → DOCX converter
```

## Replication Instructions

### Full replication (from data download)

Run scripts in numerical order. Phase 1 downloads ~9M rows from IMF APIs and takes ~30 minutes:

```bash
python3 scripts/phase1_download_data.py       # Download and construct panel
python3 scripts/phase2_estimation.py           # Main gravity models
python3 scripts/phase3_cca_robustness.py       # Robustness tests
python3 scripts/phase4_expand_yields.py        # Additional bond yields
python3 scripts/phase4b_reestimate_expanded.py # Expanded rate tests
python3 scripts/phase5_ppml.py                 # PPML estimation
python3 scripts/phase5_projections.py          # Demographics-only projections
python3 scripts/phase5b_projections_ge.py      # GDP + GE projections
python3 scripts/phase6_financial_center_robustness.py  # Financial center test
python3 scripts/wald_tests.py                  # Joint significance tests
cd paper && python3 convert_to_docx.py         # Regenerate .docx
```

### Quick verification (from provided outputs)

All estimation outputs are included in `output/tables/`. Key files:

| File | Contents |
|:-----|:---------|
| `gravity_results.csv` | Models 2a-2f (Table 2, 2b in paper) |
| `gravity_robustness.csv` | CCA exclusion (Table 4) |
| `jackknife_results.csv` | Leave-one-region-out (Table 5) |
| `financial_center_robustness.csv` | Financial center exclusion (Table 5b-ii) |
| `gravity_results_expanded.csv` | Expanded yield coverage (Table 5b) |
| `ppml_results.csv` | PPML estimates (Table 5c) |
| `mediation_decomposition.csv` | Rate vs direct channel shares |
| `bilateral_projections_ge.csv` | Full projection panel with GE |
| `projection_summary_ge.csv` | Net reallocation by country |
| `wald_tests.csv` | Joint significance tests |

### Data dependencies

Phase 1 downloads data from:
- IMF PIP database (CPIS bilateral portfolio positions)
- IMF DIP database (CDIS bilateral FDI positions)
- CEPII GeoDist (bilateral gravity variables)

Demographics are sourced from `followup/data/processed/full_panel.csv` in the parent project. The projection script also reads WEO GDP from the same panel.

## Key Results

- **Model 2b**: All ΔZ significant (p < 0.001), R² = 0.240
- **Model 2c**: KAOPEN interactions significant (p < 0.023), R² = 0.288
- **FDI null**: All demographics p > 0.37
- **Rate mediation**: 58% bilateral (vs 9% multilateral)
- **CCA robust**: Coefficients change < 7%
- **Financial center robust**: Coefficients change < 6% (narrow) to +20% (broad)
- **PPML**: Confirms OLS signs and significance
- **Projections**: KOR-IND projected to nearly triple by 2050 (GE-adjusted)
